import Taro, {Component, Config} from '@tarojs/taro'
import { View } from '@tarojs/components'
import {Loading} from "@/components/index"
import {getOrderInfo} from "@/api/orderApi"
import { getSignScore } from '@/api/userApi'
import {toOrderListPage, toOrderUnpaidPage} from "@/utils/page_router";
import {USER_INFO} from "@/config/storage";

export default class Index extends Component {
  state: any
  config: Config = {
    navigationBarTitleText: '',
  }

  constructor() {
    super(...arguments)
    const { params } = this.$router
    this.state = {
      id: params.id,
      loading: true
    }
  }

  componentDidShow() {
    const { id } = this.state
    setTimeout(() => {
      getOrderInfo(id).then(({ data }) => {
        if (data.status === 'unpaid') {
          toOrderUnpaidPage(id)
        } else {
          toOrderListPage(true)
        }
      })
      getSignScore().then(({ data }) => {
        const obj = Taro.getStorageSync(USER_INFO)
        obj.totalScore = data.totalScore
        Taro.setStorageSync(USER_INFO, obj)
      })
    }, 2000)
  }

  render() {
    const { loading } = this.state
    return (<View>
      {loading && <Loading />}
    </View>)
  }
}
